package wrs.hcs.functions;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;



public class AdminConsole_Tracker {
	
	public void goto_result_tracker(WebDriver driver){
		driver.findElement(By.xpath("//a[@href='/results/resultsTracker.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	}

	public void tracker(WebDriver driver, String pin) throws Exception{
		
		driver.findElement(By.xpath("//input[@name='pinLastName']")).sendKeys(pin);
		driver.findElement(By.xpath("//button[contains(., 'SEARCH')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//search for patient
		List<WebElement> rows = driver.findElements(By.xpath("//div[@id='table_wrapper']/div[2]/div[2]/div[2]/table/tbody/tr"));
		int size = rows.size();
		System.out.println("Result Tracker: " + size +" matches found in search");
		
		String status =  driver.findElement(By.xpath("//div[@id='table_wrapper']/div[2]/div[2]/div[2]/table/tbody/tr")).getAttribute("class");
	    String[] arr = status.split(" ");
	    for ( String ss : arr) {
	        if(ss.contains("pending_table")) {
	            System.out.println("Status is Pending Labs and PMHR");
	        }else if(ss.contains("finalReportDone_table")) {
	            System.out.println("Status is Final Report Done");
	        }else if(ss.contains("pmhrDone_table")) {
	            System.out.println("Status is PMHR Done");
	        }else if(ss.contains("urgent_table")) {
	            System.out.println("Status is Urgent");
	        }else if(ss.contains("doubleChecked_table")) {
	            System.out.println("Status is Double Checked");
	        }else if(ss.contains("dataTables_empty")){
	        	System.out.println("1 Match is empty table");
	        }
	    }
	}
	
	
	
	
}
